import io.netty.channel.ChannelHandlerContext;
import io.netty.util.AttributeKey;

public class LoginMessageResolver extends Resolver {
    @Override
    boolean support(IMessage iMessage) {
        return MessageTypeEnum.LOGIN.equals(iMessage.getType());
    }

    @Override
    IMessage resolver(IMessage iMessage, ChannelHandlerContext ctx) {
        ServerMessageHandler.channelMap.put(iMessage.getFrom(), ctx.channel());
        ctx.channel().attr(AttributeKey.valueOf("username")).set(iMessage.getFrom());
        IMessage resp = new IMessage();
        resp.setType(MessageTypeEnum.RESPONSE);
        resp.setFrom("服务器");
        resp.setTo(iMessage.getFrom());
        resp.setBody("登录成功！");
        System.out.println(iMessage.getFrom() + "登录成功！");
        return resp;
    }
}
